/*
 * GuardarJPEG.java
 *
 * Created on 12 de febrero de 2002, 10:42 PM
 */

package Utiles;

/**
 *
 * @author  Multiobjetivo
 * @version
 */


//import com.sun.image.codec.jpeg.JPEGCodec;
//import com.sun.image.codec.jpeg.JPEGEncodeParam;
//import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.io.FileOutputStream;

public class GuardarJPEG {
    
    /** Creates new GuardarJPEG */
    public GuardarJPEG(java.awt.Component parent, java.awt.image.BufferedImage image) {
        GuardarJPG(parent, image);
    }
    public static void GuardarJPG(java.awt.Component parent, java.awt.image.BufferedImage image){
        javax.swing.JFileChooser fc = new javax.swing.JFileChooser();
        String [] extensiones = new String[]{"jpg","gif"};
        ExtensionFileFilter  filter = new ExtensionFileFilter(extensiones, "Imagenes");
        fc.addChoosableFileFilter(filter);
        int returnVal = fc.showSaveDialog(parent);
        if(returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
            java.io.File f = fc.getSelectedFile();
            if(!f.getName().toLowerCase().endsWith(".jpg"))
                f = new java.io.File(f+".jpg");
            try {
//                JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(image);
//                param.setQuality(1.0f, true);
                FileOutputStream fout = new FileOutputStream(f);
//                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fout);
//                encoder.encode(image, param);
                fout.close();
            }
            catch (java.io.IOException err) {
                System.err.println("Error: "+err);
                err.printStackTrace();
            }
        }
    }
}
